

package com.ehualu.javahadoop.until;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;


public class ReadConfigurationClass {
    public static Map  readConfiguration(String path)  {
        ClassLoader classLoader = ReadConfigurationClass.class.getClassLoader();
        URL resource = classLoader.getResource(path);
        String newPath = resource.getPath();

        Properties properties = new Properties();
        //可以用两种不同的流来加载配置文件
        try {
            properties.load(new BufferedReader(new FileReader(newPath)));
        } catch (IOException e) {
            e.printStackTrace();
        }
//        try {
//            properties.load(ReadConfigurationClass.class.getResourceAsStream(path));
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        Set<Map.Entry<Object, Object>> entrySet = properties.entrySet();
        Map<Object, Object> resultMap = new HashMap<>();
        for (Map.Entry<Object, Object> entry : entrySet) {

            resultMap.put(entry.getKey(), entry.getValue());
            System.out.println(entry.getKey()+" -- "+entry.getValue());
        }

        return resultMap;


    }
}
